package com.tang.algorithm.string;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/5/18 20:06
 * 最长公共前缀
 *
 * https://leetcode-cn.com/problems/longest-common-prefix/
 */
public class LeetCode14 {
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0  ) return "";
        String res = strs[0];
        for (String str : strs){
            while (!str.startsWith(res)) {
                if (res.length() == 1) {
                    return "";
                }
                res = res.substring(0, res.length()-1);
            }
        }
        return res;
    }
}
